<template>
	<view>
		<view style="width: 100%; margin-top: 100rpx;">
			<view class="logo">
				<image src="/static/canting.png" style="width: 100%; height: 100%;"></image>

			</view>
		</view>

		<view class="title">订餐</view>


		<button
			style="border-radius: 100rpx; background: #387BF4; width: 80%;height: 97rpx; line-height: 97rpx; margin-left: 10%; margin-top: 198rpx; font-size: 31rpx; color: #fff;"
			type="primary" @click="wechatLogin">授权登录</button>


	</view>

</template>

<script>
	import {
		login
	} from '@/request/home.js'
	export default {
		data() {
			return {
				isWeixin: false
			}
		},
		onLoad() {

			// this.getAppId()
		},
		methods: {
			// 获取公众号APPID
			getAppId() {
                
				const appid = 'wx65f7bf5247a8b052';
				uni.navigateTo({
					url:'/pages/index/index'
				})
				// 2. 设置回调URL（需在微信公众号平台配置）
				const redirect_uri = encodeURIComponent('http://192.168.3.43:5173/#/pages/index/index');
				
				// 3. 构造微信授权URL
				const url =
					`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;
				
				// 4. 跳转到微信授权页面
				window.location.href = url;
				// var params = {


				// }

				// login(params).then((res) => {
				// 	console.log('成功', res);
				// 	console.log(res.data)

				// 	// 1. 获取微信公众号的AppID
				// 	const appid = res.data.AppID;

				// 	// 2. 设置回调URL（需在微信公众号平台配置）
				// 	const redirect_uri = encodeURIComponent('https://yourdomain.com/wx-callback');

				// 	// 3. 构造微信授权URL
				// 	const url =
				// 		`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect`;

				// 	// 4. 跳转到微信授权页面
				// 	window.location.href = url;

				// }).catch((err) => {
				// 	console.log('失败', err);
				// });


			},
		}
	}
</script>

<style>
	.logo {
		width: 180rpx;
		height: 180rpx;
		margin: 0 auto;
	}

	.title {
		width: 100%;
		height: 50rpx;
		text-align: center;
		font-size: 33rpx;
		font-weight: bold;
		margin-top: 33rpx;
	}

	.chuangxin {
		width: 100%;
		height: 50rpx;
		text-align: center;
		font-size: 28rpx;
		margin-top: 24rpx;
	}
</style>